package com.itheima.test16;

import java.util.TreeSet;

public class StudentDemo {
    public static void main(String[] args) {
        TreeSet<Student> treeSet = new TreeSet<>((o1, o2) -> {
            int result = o2.getAge() - o1.getAge();
            result = result == 0 ? o1.getId().compareTo(o2.getId()):result;
            return result;
        });
        //创建学生对象
        Student s1 = new Student("张三",18,"heima001");
        Student s2 = new Student("李四",18,"heima002");
        Student s3 = new Student("王五",17,"heima003");
        treeSet.add(s1);
        treeSet.add(s2);
        treeSet.add(s3);
        treeSet.forEach(student -> System.out.println(student.getId()+ "," + student.getName() + "," + student.getAge()));

    }
}
